package com.yonyou.wdt.job;

import afu.org.checkerframework.checker.oigj.qual.O;
import cn.hutool.core.map.MapUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.taobao.api.ApiException;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.yonyou.wdt.dao.JobLogDao;
import com.yonyou.wdt.entity.OpenApiURLEnum;
import com.yonyou.wdt.entity.QueryDto;
import com.yonyou.wdt.job.config.BaseConfig;
import com.yonyou.wdt.model.JobLogModel;
import com.yonyou.wdt.qimenmodel.qimencloud.api.DefaultQimenCloudClient;
import com.yonyou.wdt.qimenmodel.qimencloud.api.scenehu3cgwt0tc.request.WdtRefundOrderQueryRequest;
import com.yonyou.wdt.qimenmodel.qimencloud.api.scenehu3cgwt0tc.response.WdtRefundOrderQueryResponse;
import com.yonyou.wdt.service.YonsuiteService;
import com.yonyou.wdt.utils.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.MatchesPattern;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @ClassName YsProductToRedisJob
 * @Description YS物料档案信息同步Redis
 * @Author HuangWb
 * @Date 2023/5/12 18:35
 * @Version 1.0
 */
@Component
public class WdtProductToYsBomJob extends BaseConfig {

    private final WdtConfigProperties configProperties;

    private static Logger logger = LoggerFactory.getLogger(WdtProductToYsBomJob.class);
    @Resource
    public JobLogDao jobLogDao;
    @Resource
    private YonsuiteService yonsuiteService;

    @Autowired
    public WdtProductToYsBomJob(WdtConfigProperties configProperties) {
        this.configProperties = configProperties;
    }

    @XxlJob("WdtProductToYsBomJob")
    public ReturnT<String> wdtProductToYsBomJob(String params) throws Exception {
        String param = XxlJobHelper.getJobParam();
        Map<String, Object> map = new HashMap<>();
        if (param != null && !"".equals(param)) {
            List<String> timeRange = Arrays.asList(param.split("\\|"));
            if (timeRange.size() == 2) {
                map.put("Start", timeRange.get(0));
                map.put("End", timeRange.get(1));
            } else {
                map.put("suite_no", timeRange.get(0));
            }
        } else {
            // 默认查询前一天的数据
            map.put("Start", DateUtils.getStartDateBy60m());
            map.put("End", DateUtils.getEndDateBy60m());
        }
        String dateStr = null;
        if (map.get("Start") != null && map.get("End") != null) {
            dateStr = map.get("Start").toString() + map.get("End").toString();
        }
        // 处理相关业务
        QueryDto dto = new QueryDto();
        dto.setTenantId(getYsTenantId());
        dto.setAppKey(getYsAppKey());
        dto.setAppSecret(getYsAppSecret());
        // 获取YS系统租户动态域名信息
        ReturnT<String> isReturn2 = getYsDynamicDomainName(dto);
        // 域名获取失败
        if (isReturn2 != null) return isReturn2;
        try {
            List<JSONObject> responseList = sendWdt(map);
            Integer successCount = 0;
            Integer failCount = 0;
            // 解析数据，组装YS请求参数
            if (!responseList.isEmpty()) {
                HashMap<String, String> brandMap = getBrand();
                for (int i = 0; i < responseList.size(); i++) {
                    JSONObject jsonObject = responseList.get(i);
                    Object o = RedisUtils.get(dto.getTenantId() + ":product:" + jsonObject.getStr("suite_no"));
                    Boolean flag = Boolean.TRUE;
                    if (o == null) {
                        flag = productSave(jsonObject, dto, brandMap);
                    }
                    if (!flag) {
                        failCount++;
                        continue;
                    }
                    //Boolean flag = productSave(jsonObject, dto);
                    Map<String, Object> ysSaveParam = assembleYsParams(jsonObject, dto);
                    if (ysSaveParam == null) {
                        failCount++;
                        continue;
                    }
                    String productCode = JSONUtil.parseObj(ysSaveParam.get("data")).getStr("productCode");

                    JSONObject response = yonsuiteService.bomSave(ysSaveParam, dto);
                    if (null != response && "200".equals(response.getStr("code"))) {
                        String ysCode = response.getJSONObject("data").getStr("productCode");
                        logger.info("旺店通组合装保存YS物料清单成功");
                        InsertLogger(productCode, "1", "旺店通组合装" + productCode + "保存YS物料清单" + ysCode + "成功");
                        Map<String, Object> bomAuditReqMap = bomAuditParam(response);
                        JSONObject bomAuditRes = yonsuiteService.bomAudit(bomAuditReqMap, dto);
                        if (null != bomAuditRes && "200".equals(bomAuditRes.getStr("code"))) {
                            successCount++;
                            InsertLogger(productCode, "1", "YS物料清单审核成功");
                        } else {
                            failCount++;
                            InsertLogger(productCode, "0", "YS物料清单审核失败");
                        }
                    } else {
                        logger.error("旺店通组合装保存YS物料清单失败：{}", response.getOrDefault("message", ""));
                        String string = response.getOrDefault("message", "").toString();
                        if (string.length() > 850) {
                            string = string.substring(0, 850);
                        }
                        InsertLogger(productCode, "0", "旺店通组合装保存YS物料清单失败" + string);
                    }
                    // 处理YS接口调用频率问题
                    // 调用YS接口保存数据
                    this.APICurrentLimiting(OpenApiURLEnum.BOM_AUDIT, 19);
                    /*if (responseList.size() >= 20) {
                        Thread.sleep(3000);
                    }*/
                }
                logger.info("当前时间段：{} 需要同步到YS物料清单数据有：{}条", dateStr, responseList.size());
            }
            Thread.sleep(1000);
            InsertLogger(null, "0", "旺店通组合装一共" + responseList.size() + "条,保存YS组合装成功:" + successCount + "条，失败:" + failCount + "条。");
        } catch (Exception e) {
            logger.error("Error occurred", e);
            logger.error("旺店通组合装同步YS物料清单失败，{}", e.getMessage());
            InsertLogger(null, "0", "旺店通组合装同步YS物料清单失败" + e.getMessage());
            return ReturnT.FAIL;
        }
        logger.info("  --  旺店通组合装同步YS物料清单任务执行完成  --  ");
        return ReturnT.SUCCESS;
    }

    private Map<String, Object> bomAuditParam(JSONObject response) {
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("id", response.getJSONObject("data").getStr("id"));
        HashMap<String, Object> reqMap = new HashMap<>();
        reqMap.put("data", stringObjectHashMap);
        return reqMap;
    }

    /**
     * @return
     * @Author Huangwb
     * @Description 组装YS请求数据
     * @Date 14:34 2023/5/17
     * @Param
     **/
    private Map<String, Object> assembleYsParams(JSONObject jsonObject, QueryDto dto) throws Exception {
        Map<String, Object> saleReturnSaveMap = new HashMap<>();
        Map<String, Object> data = new HashMap<>();
        // 添加表头
        saleReturnSaveMap.put("bomType", 1);//BOM类型，1：主BOM,2:替代BOM
        saleReturnSaveMap.put("orgId", "666666");

        saleReturnSaveMap.put("materialId", jsonObject.getLong("suite_id"));//制造物料id
        String suiteNo = jsonObject.getStr("suite_no");
        saleReturnSaveMap.put("materialCode", suiteNo);//制造物料编码
        saleReturnSaveMap.put("materialName", jsonObject.getStr("suite_name"));//制造物料名称
        saleReturnSaveMap.put("productCode", jsonObject.get("suite_no"));//物料编码
        saleReturnSaveMap.put("scrap", 0);//废品率

        saleReturnSaveMap.put("versionCode", 1.00);  // 版本号，必须符合参数设置中当前组织设置的版本号格式

        saleReturnSaveMap.put("effectiveDate", jsonObject.getStr("modified"));  //生效时间

        //saleReturnSaveMap.put("expiryDate", jsonObject.getStr("modified"));  // 失效时间
        saleReturnSaveMap.put("expiryDate", "2099-10-10");  // 失效时间

        saleReturnSaveMap.put("_status", "Insert");  // 操作标识

        JSONArray items = jsonObject.getJSONArray("specs_list");
        // ==========子表============
        JSONArray details = new JSONArray();
        BigDecimal payMoney = BigDecimal.ZERO;
        for (Object element : items) {
            JSONObject item = (JSONObject) element;
            JSONObject saleReturnDetailsJson = new JSONObject();
            saleReturnDetailsJson.set("productCode", item.getStr("goods_no"));//制造物料id
            saleReturnDetailsJson.set("materialId", item.getLong("suite_id"));//制造物料id
            saleReturnDetailsJson.set("scrap", 0);//损耗率(%)，百分比值
            saleReturnDetailsJson.set("denominatorQuantity", 1);//母件底数
            saleReturnDetailsJson.set("numeratorQuantity", item.getBigDecimal("num"));//主数量    示例: 1
            saleReturnDetailsJson.set("stockNumeratorQuantity", item.getBigDecimal("num"));//母件底数
            saleReturnDetailsJson.set("supplyType", 1);//发料方式，枚举值，0：领用，1：入库倒冲，2：不发料，5：开工倒冲，6：工序倒冲
            saleReturnDetailsJson.set("effectiveDate", jsonObject.getStr("modified"));//生效时间，子件生效时间不能早于母件生效时间
            saleReturnDetailsJson.set("expiryDate", "2099-10-10");//失效时间，子件失效时间不能晚于母件失效时间
            saleReturnDetailsJson.set("isVirtual", 0);//虚拟件，枚举值，0：否，1：是
            saleReturnDetailsJson.set("usageType", 0);//用量类型，枚举值，0：固定数量，1：变动数量
            saleReturnDetailsJson.set("lossType", 0);//损耗类型，枚举值，1：固定损耗，2：变动损耗，0：无损耗
            saleReturnDetailsJson.set("truncUp", 0);//向上取整，枚举值，0：否，1：是
            saleReturnDetailsJson.set("wholeFlag", 0);//齐套，枚举值，0：否，1：是
            saleReturnDetailsJson.set("alternateType", 0);//替代方式，枚举值，0：无替代，1：部分替代，2：全部替代
            saleReturnDetailsJson.set("costScrap", item.getBigDecimal("ratio").multiply(new BigDecimal(100)));//成本比列
            saleReturnDetailsJson.set("_status", "Insert");  // 操作标识
            details.add(saleReturnDetailsJson);
        }
        saleReturnSaveMap.put("bomComponent", details);
        // saleReturnSaveMap.put("resubmitCheckKey", suiteNo);
        data.put("data", saleReturnSaveMap);
        ReSubmitUtil.resubmitCheckKey(data);
        return data;
    }

    private Boolean productSave(JSONObject jsonObject, QueryDto dto, HashMap<String, String> brandMap) throws Exception {

        // 物料详情数组
        JSONObject productList = new JSONObject();
        // 物料全参数对象集合
        JSONObject productObj = new JSONObject();
        // 物料规格对象集合
        JSONObject modelObj = new JSONObject();
        // 物料名称对象集合
        JSONObject productNameObject = new JSONObject();
        // 单位
        //String unit = jsonObject.getStr("unit");
        Integer failCount = 0;
        //主键信息
        String unit = "无";
        modelObj.set("simplifiedName", jsonObject.get("suite_name"));
        productNameObject.set("simplifiedName", jsonObject.get("suite_name"));
        productObj.set("modelDescription", modelObj);// 规格说明
        productObj.set("model", modelObj); // 型号
        productObj.set("orgCode", "global00");//管理组织 默认福建华韵竹木有限公司
        productObj.set("code", jsonObject.get("suite_no"));//物料编码
        productObj.set("productCode", jsonObject.get("suite_no"));//物料编码
        productObj.set("name", productNameObject);//物料名称
        productObj.set("manageClassCode", "DSZHJ");//物料分类编码 detailData.getJSONObject("category").get("code")
        productObj.set("realProductAttribute", "1");//物料性质，1：实物物料，2：虚拟物料
        productObj.set("realProductAttributeType", "1");//	实物物料属性，1：普通物料，2：实体卡券，3：实体储值卡，20：描述性物料，4：设备    示例: 1
        //productObj.set("virtualProductAttribute", "16");//	实物物料属性，1：普通物料，2：实体卡券，3：实体储值卡，20：描述性物料，4：设备    示例: 1
        productObj.set("unitUseType", "2");//设置规则, 1:使用物料模板的计量单位、2:使用物料自己的计量单位
        productObj.set("unitCode", unit);//主计量单位编码
        productObj.set("status", "Insert");//status操作状态：新增：Insert，删除：Delete，默认为新增
        productObj.set("autoGenerateRangeData", true);// true：自动生成组织数据，false：不自动生成组织数据。不填默认是：false。
        productObj.set("weight", jsonObject.getBigDecimal("weight").setScale(2, RoundingMode.HALF_UP));// 毛重
        productObj.set("weightUnitCode", unit);// 毛重
        if ("0".equals(jsonObject.getStr("brand_id"))) {
            productObj.set("brandCode", "无");// 品牌
        } else {
            productObj.set("brandCode", brandMap.get(jsonObject.getStr("brand_id")));// 品牌
        }
        productObj.set("useSku", "1");// 商品SKU，（1-是，0-否）
        // 物料详情组装参数
        productList.set("valueManageType", "99");//价值管理模式, 99:费用、0:存货核算、1:固定资产
        productList.set("outTaxRateCode", "NL");//价值管理模式, 99:费用、0:存货核算、1:固定资产
        productList.set("purchaseUnitCode", unit);//采购单位编码
        productList.set("inspectionUnitCode", unit);//检验单位编码
        productList.set("purchasePriceUnitCode", unit);//采购计价单位编码
        productList.set("stockUnitCode", unit);//库存单位编码
        productList.set("produceUnitCode", unit);//生产单位编码
        productList.set("batchPriceUnitCode", unit);//批发计价单位编码
        productList.set("batchUnitCode", unit);//批发销售单位编码
        productList.set("onlineUnitCode", unit);//线上零售单位编码
        productList.set("offlineUnitCode", unit);//线下零售单位编码
        productList.set("requireUnitCode", unit);//要货单位编码
        productList.set("businessAttribute", "3,7");// 业务属性, 1:采购、7:销售、3:自制、2:委外
        productList.set("saleChannel", "1,2,3");//销售渠道, 1:销售批发、2:线上零售、3:线下零售、4:微分销
        productObj.set("detail", productList);
        JSONObject productRespone = yonsuiteService.postProductSave(productObj, dto);
        Thread.sleep(1000);
        if (null != productRespone && !"200".equals(productRespone.get("code"))) {
            failCount++;
            InsertLogger(productObj.get("code").toString(), "0", "YS物料保存接口返回失败结果" + productRespone.getStr("message"));
            logger.info("YS物料保存接口返回失败结果：{}", productRespone + " 失败条数：" + productRespone.getStr("message"));
        }
        //子键信息集合
		/*JSONArray jsonArray = jsonObject.getJSONArray("specs_list");
		for (Object o : jsonArray) {
			JSONObject entries = JSONUtil.parseObj(o);
			// 物料详情数组
			 productList = new JSONObject();
			// 物料全参数对象集合
			 productObj = new JSONObject();
			// 物料规格对象集合
			 modelObj = new JSONObject();
			// 物料名称对象集合
			 productNameObject = new JSONObject();
			productObj = new JSONObject();
			modelObj.set("simplifiedName",entries.get("goods_name"));
			productNameObject.set("simplifiedName", entries.get("goods_name"));
			productObj.set("modelDescription",modelObj);// 规格说明
			productObj.set("model",modelObj); // 型号
			productObj.set("orgCode", "global00");//管理组织 默认福建华韵竹木有限公司
			productObj.set("code", entries.get("goods_no"));//物料编码
			productObj.set("productCode", entries.get("goods_no"));//物料编码
			productObj.set("name", productNameObject);//物料名称
			productObj.set("manageClassCode",jsonObject.getStr("class_name"));//物料分类编码 detailData.getJSONObject("category").get("code")
			productObj.set("realProductAttribute", "1");//物料性质，1：实物物料，2：虚拟物料
			productObj.set("realProductAttributeType", "1");//	实物物料属性，1：普通物料，2：实体卡券，3：实体储值卡，20：描述性物料，4：设备    示例: 1
			productObj.set("unitUseType", "2");//设置规则, 1:使用物料模板的计量单位、2:使用物料自己的计量单位
			productObj.set("unitCode", unit);//主计量单位编码
			productObj.set("status", "Insert");//status操作状态：新增：Insert，删除：Delete，默认为新增
			productObj.set("autoGenerateRangeData", true);// true：自动生成组织数据，false：不自动生成组织数据。不填默认是：false。
			//		productObj.set("realProductAttributeType","1"); //实物物料属性，1：普通物料，2：实体卡券，3：实体储值卡，20：描述性物料，4：设备
			productObj.set("useSku","1");// 商品SKU，（1-是，0-否）
			// 物料详情组装参数
			productList.set("purchaseUnitCode", unit);//采购单位编码
			productList.set("inspectionUnitCode", unit);//检验单位编码
			productList.set("purchasePriceUnitCode", unit);//采购计价单位编码
			productList.set("stockUnitCode", unit);//库存单位编码
			productList.set("produceUnitCode", unit);//生产单位编码
			productList.set("batchPriceUnitCode", unit);//批发计价单位编码
			productList.set("batchUnitCode", unit);//批发销售单位编码
			productList.set("onlineUnitCode", unit);//线上零售单位编码
			productList.set("offlineUnitCode", unit);//线下零售单位编码
			productList.set("requireUnitCode", unit);//要货单位编码
			productList.set("businessAttribute","1,7");// 业务属性, 1:采购、7:销售、3:自制、2:委外
			productList.set("saleChannel","1,2,3");//销售渠道, 1:销售批发、2:线上零售、3:线下零售、4:微分销
			productObj.set("detail", productList);
			productRespone = yonsuiteService.postProductSave(productObj,dto);
			Thread.sleep(1000);
			if (null != productRespone && !"200".equals(productRespone.get("code"))) {
				failCount++;
				InsertLogger(productObj.get("code").toString(), "0", "YS物料保存接口返回失败结果"+productRespone.getStr("message"));
				logger.info("YS物料保存接口返回失败结果：{}" , productRespone+" 失败条数："+productRespone.getStr("message"));
			}
		}*/
        if (failCount == 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * @Author Huangwb
     * @Description 查询YS系统租户动态域名信息
     * @Date 2023/10/30 15:45
     **/
    public ReturnT<String> getYsDynamicDomainName(QueryDto ysQueryDto) {
        try {
            String tenantId = ysQueryDto.getTenantId();  // 租户ID
            if (RedisUtils.get(tenantId + ":DynamicDomainName") == null) {
                // 根据租户ID查询动态域名
                JSONObject dynamicDomainName = yonsuiteService.getDynamicDomainName(null, tenantId);
                if (null != dynamicDomainName && !dynamicDomainName.isEmpty()) {
                    // 将动态域名存入Redis
                    RedisUtils.set(tenantId + ":DynamicDomainName", dynamicDomainName, 86400 * 30);
                } else {
                    logger.error("查询租户【{}】动态域名失败，请重试", tenantId);
                    // insertXxlJobLog(null, "0", "租户：【" + tenantId + "】获取动态域名失败，请稍后重试", jobClassType);
                    InsertLogger(null, "0", "获取动态域名失败");
                    return new ReturnT<>(ReturnT.FAIL_CODE, "查询租户【" + tenantId + "】动态域名失败，请重试");
                }
            }
            // 获取Redis中指定租户动态域名
            JSONObject dynamicDomainNameRedis = (JSONObject) RedisUtils.get(tenantId + ":DynamicDomainName");
            ysQueryDto.setGatewayUrl(dynamicDomainNameRedis.getStr("gatewayUrl"));
            ysQueryDto.setTokenUrl(dynamicDomainNameRedis.getStr("tokenUrl"));
            return null;
        } catch (Exception e) {
            return new ReturnT<>(ReturnT.FAIL_CODE, "获取动态域名失败：" + e.getMessage());
        }
    }

    private HashMap<String, String> getBrand() {
        String apiUrl = "goods_brand_query.php";
        HashMap<String, String> resList = new HashMap<>();
        WdtClient client = new WdtClient(configProperties.getSid(), configProperties.getKey(), configProperties.getSecret(), configProperties.getUrl());
        Integer realityPageNo = 0;
        HashMap<String, Object> map = new HashMap<>();
        map.put("page_no", realityPageNo.toString());
        map.put("page_size", "100");
        boolean hasNext = true;
        //总页数
        Integer totalPage = 0;
        //总条数
        Integer total_count = 0;
        while (hasNext) {
            map.put("page_no", realityPageNo.toString());
            String res = null;
            try {
                res = client.execute(apiUrl, map);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            JSONObject saleOutJson = JSONUtil.parseObj(res);
            if ("0".equals(saleOutJson.getStr("code"))) {
                //判断分页
                if (realityPageNo == 0) {
                    total_count = saleOutJson.getInt("total_count", 0);
                    totalPage = total_count % 100 == 0 ? total_count / 100 : total_count / 100 + 1;
                }
                //每页订单列表
                JSONArray orderArray = saleOutJson.getJSONArray("brand_lists");
                if (orderArray.size() > 0) {
                    List<JSONObject> list = JSONUtil.toList(orderArray, JSONObject.class);
                    for (JSONObject entries : list) {
                        resList.put(entries.getStr("brand_id"), entries.getStr("brand_no"));
                    }
                }
                //判断分页
                if (realityPageNo == 0) {
                    total_count = saleOutJson.getInt("total_count", 0);
                    totalPage = total_count % 100 == 0 ? total_count / 100 : total_count / 100 + 1;
                }
                if (totalPage > realityPageNo + 1) {
                    realityPageNo += 1;
                } else {
                    hasNext = false;
                }
            } else {
                InsertLogger(null, "0", "旺店通品牌查询失败" + saleOutJson.getStr("message"));
                break;
            }
        }
        return resList;
    }

    private List<JSONObject> sendWdt(Map<String, Object> reqMap) {
        String apiUrl = "suites_query.php";
        List<JSONObject> resList = new ArrayList<>();
        WdtClient client = new WdtClient(configProperties.getSid(), configProperties.getKey(), configProperties.getSecret(), configProperties.getUrl());
        Integer realityPageNo = 0;
        HashMap<String, Object> map = new HashMap<>();
        map.put("page_no", realityPageNo.toString());
        map.put("page_size", "100");
        if (reqMap.get("suite_no") != null) {
            map.put("suite_no", reqMap.get("suite_no"));
        } else {
            map.put("start_time", reqMap.get("Start"));
            map.put("end_time", reqMap.get("End"));
        }
        boolean hasNext = true;
        //总页数
        Integer totalPage = 0;
        //总条数
        Integer total_count = 0;
        while (hasNext) {
            map.put("page_no", realityPageNo.toString());
            String res = null;
            try {
                res = client.execute(apiUrl, map);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            JSONObject saleOutJson = JSONUtil.parseObj(res);
            if ("0".equals(saleOutJson.getStr("code"))) {
                //判断分页
                if (realityPageNo == 0) {
                    total_count = saleOutJson.getInt("total_count", 0);
                    totalPage = total_count % 100 == 0 ? total_count / 100 : total_count / 100 + 1;
                }
                //每页订单列表
                JSONArray orderArray = saleOutJson.getJSONArray("suites");
                if (orderArray.size() > 0) {
                    resList.addAll(JSONUtil.toList(orderArray, JSONObject.class));
                }
                //判断分页
                if (realityPageNo == 0) {
                    total_count = saleOutJson.getInt("total_count", 0);
                    totalPage = total_count % 100 == 0 ? total_count / 100 : total_count / 100 + 1;
                }
                if (totalPage > realityPageNo + 1) {
                    realityPageNo += 1;
                } else {
                    hasNext = false;
                }
            } else {
                InsertLogger(null, "0", "旺店通组合装接口查询失败" + saleOutJson.getStr("message"));
                break;
            }
        }
        return resList;
    }

    /**
     * @return
     * @Author Huangwb
     * @Description 插入数据库日志信息
     * @Date 10:30 2023/9/14
     * @Param
     **/
    private void InsertLogger(String code, String oneL, String mags) {  // 单据编号、是否成功、详细信息
        try {
            JobLogModel jobLogDTO = new JobLogModel();
            jobLogDTO.setJobClass("HYZM004");
            jobLogDTO.setJobCode(code);
            jobLogDTO.setJobTime(new Date());
            jobLogDTO.setJobResult(oneL);
            jobLogDTO.setJobResultMessage(mags);
            jobLogDTO.setJobLogUser("dxroot");
            jobLogDao.insertJobLog(jobLogDTO);
        } catch (Exception e) {
            logger.error("插入日志错误：" + e.getMessage());
        }
    }

}
